<?php
namespace app\admin\controller;

use think\Controller;
use think\facade\Request;

class User extends Controller {

    /**
     * @desc 登录
     */
    public function login() {
        return view();
    }

    /**
     * @desc 登录操作
     */
    public function doLogin() {
        $params['username'] = Request::post('username');
        $params['password'] = Request::post('password');
        $params['captcha']  = Request::post('captcha');

        $logic = model('User', 'logic');
        $data = [];
        try {
            $data = $logic->doLogin($params);
        } catch (\Exception $e) {
            $logic->errorCode = EC_FAILURE;
            $logic->message = $e->getMessage();
        }
        return send_response($data, $logic->errorCode, $logic->message);
    }

    /**
     * @desc 退出
     */
    public function logout() {
        header('Content-Type: text/html; charset=utf-8');
        session('memberId', null);
        $this->redirect(url('user/login'));
    }

}
